package flc.ast.dialog;

import android.content.Context;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.ToastUtils;

import flc.ast.R;
import flc.ast.databinding.DialogCreateFolderBinding;
import flc.ast.databinding.DialogSetAnswerBinding;
import stark.common.basic.base.BaseSmartDialog;

public class SetAnswerDialog extends BaseSmartDialog<DialogSetAnswerBinding> implements View.OnClickListener {

    public SetAnswerDialog(@NonNull Context context) {
        super(context);
    }

    @Override
    protected boolean canceledOnTouchOutside() {
        return true;
    }

    @Override
    protected int getGravity() {
        return Gravity.CENTER;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.dialog_set_answer;
    }

    @Override
    protected void initView(View view) {
        mDataBinding.ivCancel.setOnClickListener(this);
        mDataBinding.ivConfirm.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.ivCancel:
                dismiss();
                break;
            case R.id.ivConfirm:
                String answer = mDataBinding.etAnswer.getText().toString().trim();
                if (TextUtils.isEmpty(answer)) {
                    ToastUtils.showShort(R.string.please_input_answer);
                } else {
                    dismiss();
                    if (listener != null) {
                        listener.clickAddFolder(mDataBinding.tvQuestion.getText().toString(), answer);
                    }
                }
                break;
            default:
                break;
        }
    }

    private Ilistener listener;

    public void setListener(Ilistener listener) {
        this.listener = listener;
    }

    public interface Ilistener {
        void clickAddFolder(String question, String answer);
    }
}
